package com.cq.hd.product.controller;

import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.product.api.TbActiveRedPacketBillApi;
import com.cq.hd.product.api.dto.ActiveRedPacketBillPageDto;
import com.cq.hd.product.api.dto.MyPrizeRedPacketBillPageDto;
import com.cq.hd.product.api.dto.PointsRedPacketDto;
import com.cq.hd.product.api.vo.ActiveRedPacketBillPageVo;
import com.cq.hd.product.api.vo.MyPrizeRedPacketBillPageVo;
import com.cq.hd.product.service.TbActiveRedPacketBillService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 红包流水表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-23
 */
@RestController
public class TbActiveRedPacketBillController implements TbActiveRedPacketBillApi {

    @Autowired
    private TbActiveRedPacketBillService activeRedPacketBillService;

    @ApiOperation(value = "红包领取列表")
    @ApiResponse(response = ActiveRedPacketBillPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<ActiveRedPacketBillPageVo>> pageReceive(ActiveRedPacketBillPageDto activeRedPacketBillPageDto) {
        return ResultGenerator.success(activeRedPacketBillService.pageReceive(activeRedPacketBillPageDto));
    }

    @Override
    public Result<Page<MyPrizeRedPacketBillPageVo>> pageMyPrizeRedPacket(MyPrizeRedPacketBillPageDto myPrizeRedPacketBillPageDto) {
        return ResultGenerator.success(activeRedPacketBillService.pageMyPrizeRedPacket(myPrizeRedPacketBillPageDto));
    }

    @ApiOperation(value = "根据红包id+用户id获取红包领取记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "redPacketId", value = "红包id", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "Long")
    })
    @ApiResponse(response = ActiveRedPacketBillPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<ActiveRedPacketBillPageVo> getByRedPacketId(Long redPacketId, Long userId) {
        return ResultGenerator.success(activeRedPacketBillService.getByRedPacketId(redPacketId, userId));
    }

    @ApiOperation(value = "根据红包流水id获取红包领取记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "红包流水id", paramType = "query", dataType = "Long")
    })
    @ApiResponse(response = ActiveRedPacketBillPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<ActiveRedPacketBillPageVo> getById(Long id) {
        return ResultGenerator.success(activeRedPacketBillService.getRedPacketBillById(id));
    }

    @ApiOperation(value = "根据红包id批量获取红包流水数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "redPacketIds", value = "红包id", paramType = "query", dataType = "Long")
    })
    @ApiResponse(response = ActiveRedPacketBillPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<ActiveRedPacketBillPageVo>> listActiveRedPacketBillByRedPacketIds(@RequestBody List<Long> redPacketIds) {
        return ResultGenerator.success(activeRedPacketBillService.listActiveRedPacketBillByRedPacketIds(redPacketIds));
    }

    @ApiOperation(value = "根据商家id获取已用红包流水数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "businessId", value = "商家id", paramType = "query", dataType = "Long")
    })
    @ApiResponse(response = ActiveRedPacketBillPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<ActiveRedPacketBillPageVo>> listUsedByBusinessId(Long userId, Long businessId) {
        return ResultGenerator.success(activeRedPacketBillService.listUsedByBusinessId(userId, businessId));
    }

    @ApiOperation(value = "扫描红包过期时间，如果已过期，修改活动状态")
    @Override
    public Result<Boolean> scanRedPacketBillJob() {
        return ResultGenerator.success(activeRedPacketBillService.scanRedPacketBillJob());
    }

    @ApiOperation(value = "用户id获取红包流水数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "activeId", value = "活动id", paramType = "query", dataType = "Long")
    })
    @ApiResponse(response = ActiveRedPacketBillPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<ActiveRedPacketBillPageVo> getByActiveIdAndUserId(Long activeId, Long userId) {
        return ResultGenerator.success(activeRedPacketBillService.getByActiveIdAndUserId(userId, activeId));
    }

    @ApiOperation(value = "发放积分兑换红包")
    @ApiImplicitParam(name = "pointsRedPacketDto", value = "实体", paramType = "body", dataType = "PointsRedPacketDto")
    @Override
    public Result<Boolean> sendPointsRedPacketBill(PointsRedPacketDto pointsRedPacketDto) {
        return ResultGenerator.success(activeRedPacketBillService.sendPointsRedPacketBill(pointsRedPacketDto));
    }
}
